package host.skiree.nettydemo.config;

import host.skiree.nettydemo.protocol.Serializ;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author gcl
 * @date 2022/9/26 9:53
 */
public abstract class Config {

    static Properties properties;

    static {
        try ( InputStream in = Config.class.getResourceAsStream("/application.properties")){
            properties = new Properties();
            properties.load(in);
        }catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public static int getServerPort(){
        String port = properties.getProperty("server.port");
        if (port != null){
            return Integer.parseInt(port);
        }else {
            return 8080;
        }
    }

    public static Serializ.Type getSerializType(){
        String type = properties.getProperty("serializer.type");
        if (type != null){
            return Serializ.Type.valueOf(type);
        }else {
            return Serializ.Type.Java;
        }
    }

}
